package com.bcu.team.comment.controller;

import com.bcu.team.comment.entity.Message;
import com.bcu.team.comment.entity.User;
import com.bcu.team.comment.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Api(tags = "用户信息模块")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation(value = "查询用户")
    @GetMapping(value = "/queryUser")
    public Message<User> queryUser(Integer userId) {
        return userService.queryUser(userId);
    }


    @ApiOperation(value = "查询所有用户")
    @GetMapping(value = "/queryAllUser")
    public  Message<List<User>> getAllUser(){
        return userService.getAll();
    }

    @ApiOperation(value = "添加用户")
    @PutMapping(value = "/addUser")
    public Message addUser(User user){
        return userService.addUser(user);
    }


    @ApiOperation(value = "删除用户")
    @PutMapping(value = "/delUser")
    public Message delUser(Integer userId){
        return userService.delUser(userId);
    }

    @ApiOperation(value = "更新用户")
    @PutMapping(value = "/updateUser")
    public Message updateUser(User user){
        return userService.updateUser(user);
    }

    @ApiOperation(value="用户登录")
    @PostMapping(value = "/login")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "用户账号",required = true),
            @ApiImplicitParam(name = "userPassword",value = "密码",required = true)
    })
    public Message userLogin(@RequestParam(value = "userId") Integer userId,
                             @RequestParam(value = "userPassword") String userPassword){
        return userService.userLogin(userId,userPassword);
    }

}
